package com.rem.concurrency.multithreading.base;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 第三种创建线程池
 * 1.可以定义返回值
 * 2.可以抛出异常
 *
 * @author Rem
 * @date 2020-10-26
 */

public class Demo4 implements Callable<Boolean> {

    @Override
    public Boolean call() throws Exception {
        Thread.sleep(200);
        for (int i = 0; i < 2; i++) {
            System.err.println(Thread.currentThread().getName() + "撸代码3。。。:" + i);
        }
        return true;
    }

    public static void main(String[] args) throws Exception {
        Demo4 a = new Demo4();
        Demo4 b = new Demo4();
        Demo4 c = new Demo4();

        ExecutorService ser = Executors.newFixedThreadPool(3);
        Future<Boolean> submit = ser.submit(a);
        Future<Boolean> submit1 = ser.submit(b);
        Future<Boolean> submit2 = ser.submit(c);

        Boolean b1 = submit.get();
        Boolean b2 = submit1.get();
        Boolean b3 = submit2.get();

        ser.shutdown();

    }

}
